import AsyncStorage from '@react-native-async-storage/async-storage';
/**
 * 异步保存数据
 * @param key 保存的数据key
 * @param value 保存数据的value
 * @returns Promise(void)
 */
const save = async (key: string, value: string) => {
  try {
    return await AsyncStorage.setItem(key, value);
  } catch (error) {
    console.log(error);
  }
};

/**
 * 异步获取数据
 * @param key 保存的数据key
 * @returns Promise(value)
 */
const load = async (key: string) => {
  try {
    return await AsyncStorage.getItem(key);
  } catch (error) {
    console.log(error);
  }
};

/**
 * 异步删除数据
 * @param key 保存的数据key
 * @returns Promise(void)
 */
const remove = async (key: string) => {
  try {
    return await AsyncStorage.removeItem(key);
  } catch (error) {
    console.log(error);
  }
};

/**
 * 异步删除所有数据
 * @returns Promise(void)
 */
const clear = async () => {
  try {
    return await AsyncStorage.clear();
  } catch (error) {
    console.log(error);
  }
};

export {save, load, remove, clear};
